
import { BUS } from './event';
/**
 * 静态仓库
 */
export const STATE = {
  default: {}
};
/**
 * STATE 静态仓库属性设置
 * @param key 属性名
 * @param value 模块
 * @param module 模块名
 */
export const setStaticState = (key: string, value: any, module: string = "default" ) => {
  const moduleState = STATE[module] || {};
  moduleState[key] = value;
  STATE[module] = moduleState;
  return true;
}
/**
 *  STATE 静态仓库属性设置
 * @param key 属性名
 * @param module 模块名
 * @returns
 */
export const getStaticState = ( key: string, module: string = "default" ): any => (STATE[module] || {})[key];
export const getStaticStateModule = (module = "default") => {
  const data = STATE[module] || null;
  if (data === null) {
    STATE[module] = {};
  };
  return STATE[module];
};


export class BusState extends BUS {
  STATE = STATE;
  constructor(props) {
    super(props)
  };
  setStaticState(key: string, value: any, module: string = "default" ) {
    return setStaticState(key, value, module);
  }
  getState(key: string, module: string = 'default') {
    if (!key) {
      return {};
    }
    return getStaticState(key, module);
  }
}
export const BusAll = new BusState(STATE);